<?php 
$v_filter = "";
if(isset($_REQUEST['hdn_filter'])){
	$v_filter=_replace_bad_char(trim($_REQUEST['hdn_filter']));
}

$v_cate_id = intval($_REQUEST['hdn_report_type_id']);
$v_code = _replace_bad_char($_REQUEST['txt_code']);
$v_name = _replace_bad_char($_REQUEST['txt_name']);
$v_note = _replace_bad_char($_REQUEST['txt_note']);
$v_order = intval($_REQUEST['txt_order']);
if ($v_order==""){
	$v_order = NULL;
}
$v_status = $_REQUEST['hdn_status'];
$v_recordtype_id=$_REQUEST['hdn_recordtype_id'];
$v_recordtype=$_REQUEST['hdn_recordtype'];

//$v_form_field = 'file_xml';
//$v_file_name = _replace_bad_char(trim($_FILES[$v_form_field]['name']));
$v_file_name = _replace_bad_char($_REQUEST['file_xml']);

$v_save_and_add_new = intval($_REQUEST['hdn_save_and_add_new']);
$v_url = "/list/report/index.php?modal_dialog_mode=1" . "&hdn_report_type_id=" . $v_id . "&fuseaction=DISPLAY_SINGLE_REPORT_TYPE" ;
// Kiem tra xem nguoi dang nhap hien thoi co quyen cap nhat linh vuc hay khong?
/*
if(!_check_permission_on_function($_SESSION['staff_id'], $_ISA_APP_CODE, _CONST_LIST_CATE_UPDATE)){?>
	<script>
		alert("<? echo _CONST_FUNCTION_PERMISSION_ERROR; ?>");
		if (_MODAL_DIALOG_MODE==1){
			window.location = "<? echo $v_url; ?>";
		}else{
			window.history.back();
		}	
	</script><?
}
*/
//CSDL SQL

if(_is_sqlserver()){
	$cmd = @mssql_init("Onegate_ReportTypeUpdate",$conn);	
	@mssql_bind($cmd,"@p_report_type_id",$v_cate_id,SQLINT4);
	@mssql_bind($cmd,"@p_code",$v_code,SQLVARCHAR);
	@mssql_bind($cmd,"@p_name",$v_name,SQLVARCHAR);
	@mssql_bind($cmd,"@p_note",$v_note,SQLVARCHAR);
	@mssql_bind($cmd,"@p_file_name",$v_file_name,SQLVARCHAR);
	@mssql_bind($cmd, "@p_recordtype_id", $v_recordtype, SQLVARCHAR);

	if (is_null($v_order)){
		@mssql_bind($cmd,"@p_order",$v_order,SQLINT2, false, true, 2);
	}else{	
		@mssql_bind($cmd,"@p_order",$v_order,SQLINT2);
	}	
	@mssql_bind($cmd,"@p_status",$v_status,SQLINT1);
	$result = @mssql_execute($cmd);
	$rs = @mssql_fetch_array($result);
	$v_error = _replace_bad_char(trim($rs['RET_ERROR']));
	@mssql_free_result($result);
}

if (!is_null($v_error) and $v_error<>""){?>
	<script>
		alert("<?php echo $v_error; ?>");
		if (_MODAL_DIALOG_MODE==1){
			window.location = "<?php echo $v_url; ?>";
		}else{
			window.history.back();
		}	
	</script><?php
	exit;
}
sleep(0);
?>
<form action="index.php" method="post" name="f_back">
	<input type="hidden" name="fuseaction" value="DISPLAY_ALL_REPORT_TYPE">
	<input type="hidden" name="hdn_item_id" value="<?php echo $v_id;?>">
	<input name="hdn_filter" type="hidden" value="<?php echo $v_filter; ?>">
	<input name="hdn_recordtype_id" type="hidden" value="<?php echo $v_recordtype_id; ?>">
</form>
<Script language="javascript">
	if ("<?php echo $v_save_and_add_new; ?>" != "1")
		return_value = "<?php echo $v_id; ?>" + _LIST_DELIMITOR + "<?php echo $v_code; ?>"  + _LIST_DELIMITOR + "<?php echo $v_name; ?>" 
	else
		return_value = "";
	goto_after_update_data(<?php echo $v_save_and_add_new; ?>, "DISPLAY_SINGLE_REPORT_TYPE",return_value);
</Script>
